<template>
  <div class="mainsu">
    <div class="main_spac1">
      <div class="main_white padding10 paddingBottom20">
        <div class="mainor_form">
          <div class="mainor_te">
            <el-button class="mainor_tea" @click="allotTypeDia"
              >新增调拨</el-button
            >

            <el-button
              @click="
                () => {
                  exportbuVisible = true;
                }
              "
              >导出</el-button
            >
          </div>
          <el-form
            :inline="true"
            :model="form"
            class="demo-form-inline"
            ref="userListFrom"
            label-width="70px"
          >
            <el-form-item label="调拨时间" prop="createTime">
              <el-date-picker
                v-model="createTime"
                type="daterange"
                class="time220"
                :editable="false"
                unlink-panels
                range-separator="至"
                start-placeholder="开始日期"
                end-placeholder="结束日期"
                value-format="yyyy-MM-dd"
                :clearable="false"
                :picker-options="pickerOptions"
              />
            </el-form-item>
            <el-form-item label="商品" prop="goods_spu_id">
              <change-goods-input
                ref="changeGoodsInput"
                @clear="
                  () => {
                    this.form.goods_spu_id = '';
                  }
                "
                @sendValue="
                  (data) => {
                    this.form.goods_spu_id = data.id;
                  }
                "
              ></change-goods-input>
            </el-form-item>
            <el-form-item label="单号" prop="order_sn">
              <el-input
                v-model.trim="form.order_sn"
                placeholder="单号"
                clearable
                class="wid220"
              ></el-input>
            </el-form-item>
            <el-form-item>
              <el-button
                class="reset marginLeft10"
                type="primary"
                @click="
                  $refs['userListFrom'].resetFields(),
                    (createTime = []),
                    ($refs['changeGoodsInput'].name = '')
                "
                >重置</el-button
              >
              <el-button
                type="primary"
                @click="getArticleList"
                :loading="listLoading"
                >搜索</el-button
              >
            </el-form-item>
          </el-form>
        </div>
        <div class="main_table marginTop10" style="min-height: 550px">
          <el-table
            ref="multipleTable"
            v-loading="listLoading"
            :data="list.list.data"
            element-loading-text="加载中"
            fit
            border
            highlight-current-row
            @selection-change="handleSelectionChange"
            :header-cell-class-name="this.$verticaline"
          >
            <el-table-column type="selection"></el-table-column>
            <el-table-column label="调拨单号" max-width="150" prop="order_sn" />
            <el-table-column label="调拨类型" width="110" prop="order_sn">
              <template slot-scope="scope">
                <span :class="'type' + scope.row.type">{{
                  typeList[scope.row.type]
                }}</span>
              </template>
            </el-table-column>
            <el-table-column
              label="商品信息"
              min-width="220"
              prop="goods_content"
              align="center"
            >
              <template slot-scope="scope">
                <span style="color: #67c23a">{{
                  scope.row.goods_content
                }}</span>
              </template>
            </el-table-column>

            <el-table-column label="备注" min-width="150" prop="remark" />
            <el-table-column
              label="调拨时间"
              show-overflow-tooltip
              max-width="160"
              fixed="right"
              prop="created_at"
            >
              <template slot-scope="scope">{{
                parseTime(scope.row.created_at)
              }}</template>
            </el-table-column>
          </el-table>
        </div>
        <div class="main_page boxdq">
          <div></div>
          <!-- 分页 -->
          <div class="main_page_r">
            <el-pagination
              :current-page="current.page"
              :page-sizes="[20, 30, 50, 100]"
              :page-size="limit"
              layout="total, sizes, prev, pager, next, jumper"
              :total="totalCount"
              background
              @size-change="changeLimit"
              @current-change="changePage"
            />
          </div>
        </div>

        <!-- 调拨类型选择 -->
        <el-dialog
          title="调拨类型选择"
          :close-on-click-modal="false"
          :close-on-press-escape="false"
          :visible.sync="allot_type_show"
          class="main_dialog_copy dialog400"
        >
          <div class="allot_type_container">
            <div class="upload_box flex-center" @click="changeAllotType(1)">
              同商品调拨
            </div>
            <div class="upload_box flex-center" @click="changeAllotType(2)">
              异商品调拨
            </div>
          </div>
        </el-dialog>

        <!-- 同商品调拨 -->
        <el-dialog
          title="同商品调拨"
          :close-on-click-modal="false"
          :close-on-press-escape="false"
          @close="closeDia(1)"
          :visible.sync="addedFormVisible"
          class="main_dialog dialog550"
        >
          <el-form
            :inline="false"
            :model="info"
            :rules="rules"
            class="demo-form-inline"
            ref="userListFrom1"
            label-width="140px"
          >
            <el-form-item label="选择商品：" prop="name">
              <allot-change-goods
                ref="sysncGoodsInput"
                url="sync"
                @clear="sysncClose"
                @sendValue="handleSelect"
              ></allot-change-goods>
            </el-form-item>
            <el-form-item label="选择调出SKU：" prop="stock_out_goods_spu_id">
              <el-select
                v-model="info.stock_out_goods_spu_id"
                placeholder="选择调出SKU"
                class="wid300"
                @change="spuChange(1)"
              >
                <template v-for="item in formsp.arry">
                  <el-option
                    :key="item.id"
                    :label="item.spu_name.title"
                    :value="item.id"
                    v-if="item.id != info.storage_goods_spu_id"
                  ></el-option>
                </template>
              </el-select>
            </el-form-item>
            <el-form-item label="调出SKU库存：" prop="inventory_num">
              <el-input
                v-model.trim="info.inventory_num"
                placeholder="调出SKU库存"
                clearable
                :disabled="true"
                class="wid300"
              ></el-input>
            </el-form-item>
            <el-form-item label="调出数量：" prop="stock_out_num">
              <el-input
                v-model.trim="info.stock_out_num"
                placeholder="调出数量"
                class="wid300"
                clearable
                @clear="numberClear"
                @change="numberChange"
                @input="stockInput"
              ></el-input>
            </el-form-item>
            <el-form-item label="选择调入SKU：" prop="storage_goods_spu_id">
              <el-select
                v-model.trim="info.storage_goods_spu_id"
                placeholder="选择调入SKU"
                class="wid300"
                @change="spuChange(2)"
              >
                <template v-for="item in formsp.arry">
                  <el-option
                    :key="item.id"
                    :label="item.spu_name.title"
                    :value="item.id"
                    v-if="item.id != info.stock_out_goods_spu_id"
                  ></el-option>
                </template>
              </el-select>
            </el-form-item>
            <el-form-item label="调入数量：">
              <el-input
                v-model.trim="info.transfer"
                placeholder="调入数量"
                clearable
                :disabled="true"
                class="wid300"
              ></el-input>
            </el-form-item>
            <el-form-item label="互调比：">
              <el-input
                v-model.trim="info.ratio"
                placeholder="互调比"
                clearable
                :disabled="true"
                class="wid300"
              ></el-input>
            </el-form-item>
            <el-form-item label="备注：" prop="remark">
              <el-input
                v-model.trim="info.remark"
                placeholder="备注"
                clearable
                class="wid300"
              ></el-input>
            </el-form-item>
          </el-form>
          <div slot="footer" class="dialog-footer">
            <el-button @click="(addedFormVisible = false), sysncClose()"
              >取 消</el-button
            >
            <el-button type="primary" @click="setupmine" v-repeatClick
              >保 存</el-button
            >
          </div>
        </el-dialog>

        <!-- 异商品调拨 -->
        <el-dialog
          title="异商品调拨"
          :close-on-click-modal="false"
          :close-on-press-escape="false"
          :visible.sync="asyncGoodsVisible"
          @close="closeDia(2)"
          class="main_dialog dialog550"
        >
          <el-form
            :inline="false"
            :model="asyncGoodsForm"
            :rules="rules"
            class="demo-form-inline"
            ref="asyncGoodsForm"
            label-width="140px"
          >
            <el-form-item label="调出商品：" prop="name">
              <allot-change-goods
                ref="asysncGoodsInput1"
                :form="asyncGoodsForm"
                :type="1"
                url="async"
                @clear="asyncClear(1)"
                @sendValue="
                  (item) => {
                    handleSelectAsync(item, 1);
                  }
                "
              ></allot-change-goods>
            </el-form-item>
            <!-- <el-form-item label="选择调出SKU：" prop="stock_out_goods_spu_id">
              <el-select
                v-model.trim="asyncGoodsForm.stock_out_goods_spu_id"
                placeholder="选择调出SKU"
                class="wid300"
                @change="asyncSpuChange(1)"
              >
                <template v-for="item in stock_out_goods_spu">
                  <el-option
                    :key="item.id"
                    :label="item.spu_name.title"
                    :value="item.id"
                  ></el-option>
                </template>
              </el-select>
            </el-form-item> -->
            <el-form-item label="系统库存:">
              <el-input
                v-model.trim="asyncGoodsForm.inventory_num"
                placeholder="系统库存"
                clearable
                :disabled="true"
                class="wid300"
              ></el-input>
            </el-form-item>
            <el-form-item label="调出数量：" prop="stock_out_num">
              <el-input
                v-model.trim="asyncGoodsForm.stock_out_num"
                placeholder="调出数量"
                class="wid300"
                clearable
              ></el-input>
            </el-form-item>
            <el-form-item label="调入商品：" prop="storage_name">
              <allot-change-goods
                ref="asysncGoodsInput2"
                :form="asyncGoodsForm"
                :type="2"
                url="async"
                @clear="asyncClear(2)"
                @sendValue="
                  (item) => {
                    handleSelectAsync(item, 2);
                  }
                "
              ></allot-change-goods>
            </el-form-item>
            <!-- <el-form-item label="选择调入SKU：" prop="storage_goods_spu_id">
              <el-select
                v-model.trim="asyncGoodsForm.storage_goods_spu_id"
                placeholder="选择调入SKU"
                class="wid300"
              >
                <template v-for="item in storage_goods_spu">
                  <el-option
                    :key="item.id"
                    :label="item.spu_name.title"
                    :value="item.id"
                  ></el-option>
                </template>
              </el-select>
            </el-form-item> -->

            <el-form-item label="调入数量：" prop="storage_num">
              <el-input
                v-model.trim="asyncGoodsForm.storage_num"
                placeholder="调入数量"
                class="wid300"
                clearable
              ></el-input>
            </el-form-item>
            <el-form-item label="备注：" prop="remark">
              <el-input
                v-model.trim="asyncGoodsForm.remark"
                placeholder="备注"
                clearable
                class="wid300"
              ></el-input>
            </el-form-item>
          </el-form>
          <div slot="footer" class="dialog-footer">
            <el-button @click="(asyncGoodsVisible = false), sysncClose()"
              >取 消</el-button
            >
            <el-button type="primary" @click="asyncSetupmine" v-repeatClick
              >保 存</el-button
            >
          </div>
        </el-dialog>

        <!-- SKU调拨导出 -->
        <el-dialog
          title="订单导出"
          :visible.sync="exportbuVisible"
          class="main_dialog dialog500"
        >
          <div v-if="selectArr.length == 0 ? true : false">
            <p class="exptitle">选择导出时间</p>
            <el-date-picker
              v-model="exportTime"
              type="daterange"
              range-separator="至"
              start-placeholder="开始日期"
              end-placeholder="结束日期"
              format="yyyy-MM-dd"
              value-format="yyyy-MM-dd"
              @change="datepicker"
            >
            </el-date-picker>
            <el-tooltip
              class="item"
              effect="dark"
              content="时间范围只能选择一个月之内"
              placement="top"
            >
              <i class="el-icon-question"></i>
            </el-tooltip>
          </div>
          <div v-if="selectArr.length == 0 ? false : true" class="maintip">
            你已经选择了<span>{{ selectArr.length }}</span
            >行数据
          </div>
          <div slot="footer" class="dialog-footer">
            <el-button @click="exportbuVisible = false">取 消</el-button>
            <el-button type="primary" @click="exportConfirm" v-repeatClick
              >确 定</el-button
            >
          </div>
        </el-dialog>
      </div>
    </div>
  </div>
</template>

<script>
const shuju = {
  formsp: {
    name: [],
    arry: [],
    value: "",
  },
};

import {
  allocation_index,
  allocation_add,
  allocation_getGoods,
  allocation_getGoodsSpu,
  export_allocation_info,
  allocation_addDiff,
} from "@/api/warehouse/warehouseAllocation";
import { apiUrl, objKeySort, Md5 } from "@/utils/public";
import rules from "@/rules/warehouse/warehouseAllocation";
import dateOption from "@/options/dateOption";
import { parseTime, exportMethod } from "@/utils/index";
import AllotChangeGoods from "@/views/warehouse/components/AllotChangeGoods";

export default {
  components: { AllotChangeGoods },
  data() {
    return {
      // 时间
      parseTime,
      exportMethod,
      // 验证
      rules,
      import_sku: "",
      import_skudata: {},
      typeList: {
        1: "同商品",
        2: "异商品",
      },
      // 增加
      info: {
        goods_id: "",
        stock_out_goods_spu_id: null,
        storage_goods_spu_id: null,
        stock_out_num: "",
        remark: "",
        inventory_num: "",
        name: "",
        transfer: "",
        ratio: "",
        type: 1,
      },
      formsp: {
        name: [],
        arry: [],
        value: "",
      },
      addedFormVisible: false,

      // 异步商品调拨
      asyncGoodsVisible: false,
      asyncGoodsForm: {
        goods_id: "",
        name: "",
        stock_out_goods_spu_id: "",
        inventory_num: "",
        stock_out_num: "", //调出数量
        storage_goods_id: "",
        storage_name: "",
        storage_goods_spu_id: "",
        storage_num: "",
        remark: "",
        type: 2,
      },
      storage_goods_spu: [],
      stock_out_goods_spu: [],
      // 调拨类型选择
      allot_type_show: false,

      // 分页
      current: {
        page: 1,
        per_page: 20,
      },
      limit: 20,
      totalCount: 1,
      // 列表数据
      list: {
        list: [],
      },
      listLoading: false,
      // 搜索
      form: {
        goods_spu_id: "",
        order_sn: "",
        start_time: "",
        end_time: "",
      },
      createTime: [],
      pickerOptions: dateOption,
      // 选择全部
      selectArr: [],
      // 导出
      exportbuVisible: false,
      // 导出时间
      exportTime: "",
    };
  },
  created() {
    // 列表
    this.allocation_index();
    this.import_sku = process.env.VUE_APP_BASE_API + "/import/import_sku";
  },
  methods: {
    // 同步弹窗关闭
    sysncClose() {
      this.info = {
        goods_id: "",
        stock_out_goods_spu_id: null,
        storage_goods_spu_id: null,
        stock_out_num: "",
        remark: "",
        inventory_num: "",
        name: "",
        transfer: "",
        ratio: "",
        type: 1,
      };
      this.$refs["sysncGoodsInput"].name = "";
      this.formsp = JSON.parse(JSON.stringify(shuju.formsp));
      this.$refs["userListFrom1"].clearValidate();
    },
    // 异步弹窗关闭
    asyncClose() {
      this.asyncGoodsForm = {
        goods_id: "",
        name: "",
        stock_out_goods_spu_id: "",
        inventory_num: "",
        stock_out_num: "", //调出数量
        storage_goods_id: "",
        storage_name: "",
        storage_goods_spu_id: "",
        storage_num: "",
        remark: "",
        type: 2,
      };
      this.$refs["asysncGoodsInput1"].name = "";
      this.$refs["asysncGoodsInput2"].name = "";
      this.$refs["asyncGoodsForm"].clearValidate();
    },
    asyncClear(type) {
      switch (type) {
        case 1:
          this.asyncGoodsForm.goods_id = "";
          this.asyncGoodsForm.name = "";
          this.asyncGoodsForm.inventory_num = "";
          this.asyncGoodsForm.stock_out_goods_spu_id = "";
          this.$refs["asysncGoodsInput1"].name = "";
          break;
        case 2:
          this.asyncGoodsForm.storage_goods_id = "";
          this.asyncGoodsForm.storage_name = "";
          this.asyncGoodsForm.storage_goods_spu_id = "";
          this.$refs["asysncGoodsInput2"].name = "";
          break;
      }
    },
    // 弹窗关闭
    closeDia(type) {
      this.allot_type_show = false;
      switch (type) {
        case 1:
          this.$nextTick(() => {
            this.sysncClose();
          });
          break;

        case 2:
          this.$nextTick(() => {
            this.asyncClose();
          });
          break;
      }
    },
    // 同步商品确认
    setupmine() {
      this.$refs["userListFrom1"].validate((valid) => {
        if (valid) {
          let info = JSON.parse(JSON.stringify(this.info));
          let { inventory_num, name, transfer, ratio, ...from } = info;
          let data = Object.assign(
            {
              sign: Md5(
                objKeySort(Object.assign(apiUrl().name, from)) +
                  apiUrl().appsecret
              ),
            },
            apiUrl().name,
            from
          );
          allocation_add(data).then((res) => {
            this.addedFormVisible = false;
            if (res.errcode == 0) {
              this.$message({
                message: "新增成功",
                type: "success",
              });
              this.current.page = 1;
              this.allocation_index();
            } else {
              this.$message.error(res.errmsg);
            }
          });
        }
      });
    },
    //异步商品确认
    asyncSetupmine() {
      this.$refs["asyncGoodsForm"].validate((valid) => {
        if (valid) {
          let data = Object.assign(
            {
              sign: Md5(
                objKeySort(Object.assign(apiUrl().name)) + apiUrl().appsecret
              ),
            },
            apiUrl().name,
            this.asyncGoodsForm
          );
          allocation_addDiff(data).then((res) => {
            if (res.errcode == 0) {
              this.asyncGoodsVisible = false;
              this.$message({
                message: "新增成功",
                type: "success",
              });
              this.current.page = 1;
              this.allocation_index();
            } else {
              this.$message.error(res.errmsg);
            }
          });
        } else {
        }
      });
    },
    // 商品搜索
    querySearchAsync(queryString, cb) {
      if (queryString.trim() == "") {
        cb([]);
        return;
      }
      let data = Object.assign(
        {
          sign: Md5(
            objKeySort(
              Object.assign(apiUrl().name, { name: queryString.trim() })
            ) + apiUrl().appsecret
          ),
        },
        apiUrl().name,
        { name: queryString.trim() }
      );
      allocation_getGoods(data).then((res) => {
        if (res.errcode == 0) {
          var results = res.data.goods;
          if (this.$refs.searchSelect) {
            this.$refs.searchSelect.activated = true;
          }
          cb(results);
        } else {
          this.$message.error(res.errmsg);
          cb([]);
        }
      });
    },
    // 异商品选择
    handleSelectAsync(item, type) {
      switch (type) {
        case 1:
          this.asyncGoodsForm.goods_id = item.goods_id;
          this.asyncGoodsForm.name = item.name;
          this.$refs["asyncGoodsForm"].clearValidate("name");
          this.asyncGoodsForm.inventory_num = item.inventory.num;
          this.asyncGoodsForm.stock_out_goods_spu_id = item.id;

          break;
        case 2:
          this.asyncGoodsForm.storage_goods_id = item.goods_id;
          this.asyncGoodsForm.storage_name = item.name;
          this.$refs["asyncGoodsForm"].clearValidate("storage_name");
          this.asyncGoodsForm.storage_goods_spu_id = item.id;

          break;
      }
    },

    // 异商品sku选择
    asyncSpuChange(type) {
      switch (type) {
        case 1:
          this.stock_out_goods_spu.map((e) => {
            if (this.asyncGoodsForm.stock_out_goods_spu_id == e.id) {
              this.asyncGoodsForm.inventory_num = e.inventory.num;
            }
          });
          break;
        case 2:
          break;
      }
    },
    // 同商品选择
    handleSelect(item) {
      this.formsp.name = item;
      this.info.goods_id = item.id;
      this.info.name = item.name;
      this.formsp.value = item.name;
      this.allocation_getGoodsSpu();
    },
    allocation_getGoodsSpu() {
      let formsp = JSON.parse(JSON.stringify(this.formsp));
      let data = Object.assign(
        {
          sign: Md5(
            objKeySort(
              Object.assign(apiUrl().name, {
                goods_id: formsp.name.id,
              })
            ) + apiUrl().appsecret
          ),
        },
        apiUrl().name,
        {
          goods_id: formsp.name.id,
        }
      );
      allocation_getGoodsSpu(data).then((res) => {
        if (res.errcode == 0) {
          this.formsp.arry = res.data.list;
        } else {
          this.close();
          this.$message.error(res.errmsg);
        }
      });
      this.$refs["userListFrom1"].clearValidate();
    },
    spuChange(type) {
      let stock_package_num = "";
      let storage_package_num = "";
      this.formsp.arry.map((e) => {
        if (this.info.stock_out_goods_spu_id == e.id) {
          stock_package_num = e.package_num;
          if (type == 1) {
            this.info.inventory_num = e.inventory ? e.inventory.num : "0.00";
          }
        }
        if (this.info.storage_goods_spu_id == e.id) {
          storage_package_num = e.package_num;
        }
      });
      if (this.info.stock_out_goods_spu_id && this.info.storage_goods_spu_id) {
        this.info.ratio = this.$toFixed(
          parseFloat(stock_package_num) / parseFloat(storage_package_num)
        );
      }
      if (parseFloat(this.info.ratio) && parseFloat(this.info.stock_out_num)) {
        this.info.transfer = this.$toFixed(
          parseFloat(this.info.ratio) * parseFloat(this.info.stock_out_num)
        );
      }
    },
    stockInput(val) {
      if (parseFloat(this.info.ratio) && parseFloat(val)) {
        this.info.transfer = this.$toFixed(
          parseFloat(this.info.ratio) * parseFloat(val)
        );
      }
    },
    // 监听输入
    numberChange(val) {
      if (parseFloat(val) <= parseFloat(this.info.inventory_num)) {
        this.info.stock_out_num = parseFloat(val);
      } else {
        this.info.stock_out_num = parseFloat(this.info.inventory_num);
      }
    },
    numberClear() {
      this.info.stock_out_num = 0;
    },
    // 搜索
    getArticleList() {
      this.current.page = 1;
      this.allocation_index();
    },
    // 分页
    changeLimit(pageSize) {
      this.current.per_page = pageSize;
      this.allocation_index();
    },
    changePage(page) {
      this.current.page = page;
      this.allocation_index();
    },
    // 列表
    allocation_index() {
      this.listLoading = true;
      let data = Object.assign(
        {
          sign: Md5(
            objKeySort(
              Object.assign(apiUrl().name, this.list_form(), this.current)
            ) + apiUrl().appsecret
          ),
        },
        apiUrl().name,
        this.list_form(),
        this.current
      );
      allocation_index(data).then((res) => {
        this.listLoading = false;
        if (res.errcode == 0) {
          this.list = res.data;
          res.data.list.data.map((e) => {
            e.goods_content = "";
            let str = "";
            if (e.type == 1) {
              if (e.goods.transfer == 1) {
                str = `${e.goods.name} ${e.stock_out_num}${e.stock_out_goods_spu.spu_unit.title}  --->  
                ${e.goods.name} ${e.storage_num}${e.storage_goods_spu.spu_unit.title}`;
              } else if (e.goods.transfer == 0) {
                str = `${e.goods.name} 【${e.stock_out_goods_spu.spu_name.title}】  ${e.stock_out_num}${e.stock_out_goods_spu.spu_unit.title}  --->  
                ${e.goods.name}【${e.storage_goods_spu.spu_name.title}】 ${e.storage_num}${e.storage_goods_spu.spu_unit.title}`;
              }
            } else if (e.type == 2) {
              str = `${e.goods.name}【${e.stock_out_goods_spu.spu_name.title}】 ${e.stock_out_num}${e.stock_out_goods_spu.spu_unit.title}  --->   
                ${e.storage_goods.name}【${e.storage_goods_spu.spu_name.title}】 ${e.storage_num}${e.storage_goods_spu.spu_unit.title}`;
            }
            e.goods_content = str;
          });
          this.totalCount = res.data.list.total;
        } else {
          this.$message.error(res.errmsg);
        }
      });
    },
    list_form() {
      let form = JSON.parse(JSON.stringify(this.form));
      form.start_time = this.createTime[0] ? this.createTime[0] : "";
      form.end_time = this.createTime[1] ? this.createTime[1] : "";

      return form;
    },
    // 监听表单全选事件
    // 监听全选
    handleSelectionChange(val) {
      this.selectArr = [];
      val.map((item) => {
        this.selectArr.push({ id: item.id });
      });
      console.log(this.selectArr);
    },
    exportConfirm() {
      let ids = [];
      let send_time = "";
      if (this.selectArr.length > 0) {
        this.selectArr.forEach((item) => {
          ids.push(item.id);
        });
      }
      if (this.exportTime.length > 0) {
        send_time = this.exportTime.join(" ");
      }
      let form = {
        ids: ids.join("-"),
        send_time: send_time,
      };
      let data = Object.assign(
        {
          sign: Md5(
            objKeySort(Object.assign(apiUrl().name, form)) + apiUrl().appsecret
          ),
        },
        apiUrl().name,
        form
      );
      this.exportbuVisible = false;
      export_allocation_info(data)
        .then((res) => {
          this.exportMethod(res, "sku调拨单");
        })
        .catch(() => {
          this.$message.error("导出失败");
        });
    },
    // 导出时间范围
    datepicker(val) {
      let start = "";
      let end = "";
      if (val) {
        start = new Date(val[0]).getTime();
        end = new Date(val[1]).getTime();
        if (end - start > 30 * 24 * 60 * 60 * 1000) {
          this.$message.error("选择范围不能超过一个月，请重新选择");
          this.exportTime = "";
        }
      }
    },

    // 选择调拨类型
    allotTypeDia() {
      this.allot_type_show = true;
    },
    changeAllotType(type) {
      switch (type) {
        case 1:
          this.$nextTick(() => {
            this.addedFormVisible = true;
          });
          break;
        case 2:
          this.$nextTick(() => {
            this.asyncGoodsVisible = true;
          });
          break;
      }
    },
  },
};
</script>
<style lang="scss" scoped>
@import "@/styles/variables.scss";

.mainsu {
  .mainor_form form {
    width: calc(100% - 100px);
  }
}

// 导出订单表头
.exptitle {
  display: block;
  font-size: 16px;
  color: #000000;
  margin: 0 0 10px;
}
.maintip {
  text-align: center;
  padding-top: 15px;
  font-size: 18px;
  span {
    display: inline;
    padding: 18px 0;
    color: red;
  }
}
.type1 {
  color: #03a98e;
}
.type2 {
  color: red;
}
// 导入
.importForm {
  display: flex;
  align-items: center;
  justify-content: center;
}
.allot_type_container {
  display: flex;
  align-items: center;
  justify-content: space-around;
  & > div {
    width: 90px;
    height: 90px;
    margin: 10px 0;
    text-align: center;
    line-height: 90px;
    font-size: 14px;
    color: #ccc;
    border: 1px dashed #e6e6e6;
    cursor: pointer;
    &:hover {
      color: #03a98e;
      border-color: #03a98e;
    }
  }
}
.main_dialog_copy {
  /deep/ .el-dialog {
    margin-top: 30vh !important;
  }
}
</style>
